<template>
<div>
  <el-select v-model="kuweikeyid" size="small" style="width:100%" filterable clearable @change="returnChange" placeholder="请选择库位" >
    <el-option 
      v-for="item in kuweis" 
      :key="item.kuweiId" 
      :label="item.kuweiName" 
      :value="item.kuweiId">
    </el-option>
  </el-select>
  </div>
</template>

<script>
import { listKuwei } from "@/api/erp/system/kuwei";

export default {
  data() {
    return {
      kuweis:[],
      kuweikeyid : '',
    };
  },
  model:{
    prop:'kuweiId',
    event: 'change'
  },
  watch:{
    kuweiId : function(newValue, oldValue){
      this.kuweikeyid = newValue;
    },
    cangkuId: function(newValue, oldValue){
      this.listkuweis({cangkuId: newValue});
    }
  },
  props: {
    //用于绑定和初始选中的仓库ID
    kuweiId : 0,
    //所属仓库ID
    cangkuId : 0,
  },
  methods: {
    returnChange(){
      this.$emit('change', this.kuweikeyid);
    },
    listkuweis(){
      listKuwei({cangkuId : this.cangkuId == null || this.cangkuId == '' ? -1 : this.cangkuId }).then(response => {
        this.kuweis = response.rows;
      });    
    }
  },
  created() {
    this.listkuweis({cangkuId: this.cangkuId});
  },
  mounted(){
  },
};
</script>
